import sys

from PyQt5 import QtWidgets
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import QHBoxLayout, QApplication, QLayout, QWidget
from PyQt5.QtCore import Qt, QSize


class CommandList(QWidget):
    def __init__(self):
        super().__init__()
        self.Command_List_Widget = QtWidgets.QListWidget()
        self.Command_List_Widget.setWindowFlags(Qt.FramelessWindowHint)
        self.setUi()

    def setUi(self):
        self.Command_List_Widget.setFixedSize(400, 770)
        self.add_title()
        self.add_one_command_list("AT")
        self.add_one_command_list("AT+GMR")
        for i in range(0, 48):
            self.add_one_command_list("")

    def add_one_command_list(self, command):
        layout = QHBoxLayout()
        layout.setSpacing(0)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setStretch(0, 0)
        layout.setSizeConstraint(QLayout.SetFixedSize)
        # 添加复选框
        ishex = QtWidgets.QCheckBox()
        ishex.setFixedSize(15, 15)
        ishex.setStyleSheet("QCheckBox::indicator{subcontrol-position:center center;}")
        layout.addWidget(ishex)

        # 添加命令
        text = QtWidgets.QLineEdit()
        text.setFixedSize(220, 15)
        text.setFont(QFont("楷体", 6))
        text.setText(command)
        layout.addWidget(text)
        # 添加注释/发送按钮
        button = QtWidgets.QPushButton()
        button.setFixedSize(115, 15)
        button.setStyleSheet("QPushButton{text-align:left}")
        button.setFont(QFont("楷体", 6))
        button.setText("未注释")
        layout.addWidget(button)
        # 添加序号
        index = QtWidgets.QLineEdit()
        index.setFixedSize(15, 15)
        index.setFont(QFont("楷体", 6))
        index.setText("0")
        layout.addWidget(index)
        # 添加延时时间
        delay_time = QtWidgets.QLineEdit()
        delay_time.setFixedSize(25, 15)
        delay_time.setFont(QFont("楷体", 6))
        delay_time.setText("1000")
        layout.addWidget(delay_time)
        # 布局
        weight = QtWidgets.QWidget()
        weight.setLayout(layout)
        item = QtWidgets.QListWidgetItem()
        item.setSizeHint(QSize(370, 15))
        self.Command_List_Widget.addItem(item)
        self.Command_List_Widget.setItemWidget(item, weight)

    def add_title(self):
        layout = QHBoxLayout()
        layout.setSpacing(0)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setStretch(0, 0)
        layout.setSizeConstraint(QLayout.SetFixedSize)
        isHex_title = QtWidgets.QLabel()
        isHex_title.setFixedSize(15, 15)
        isHex_title.setText("HEX")
        isHex_title.setFont(QFont("楷体", 6))
        # 居中
        isHex_title.setAlignment(Qt.AlignCenter)
        layout.addWidget(isHex_title)
        command_title = QtWidgets.QLabel()
        command_title.setFixedSize(220, 15)
        command_title.setText("命令")
        command_title.setFont(QFont("楷体", 6))
        # 居中
        command_title.setAlignment(Qt.AlignCenter)
        layout.addWidget(command_title)
        button_title = QtWidgets.QLabel()
        button_title.setFixedSize(115, 15)
        button_title.setText("注释/发送")
        button_title.setFont(QFont("楷体", 6))
        # 居中
        button_title.setAlignment(Qt.AlignCenter)
        layout.addWidget(button_title)
        index_title = QtWidgets.QLabel()
        index_title.setFixedSize(15, 15)
        index_title.setText("序号")
        index_title.setFont(QFont("楷体", 6))
        index_title.setAlignment(Qt.AlignCenter)
        layout.addWidget(index_title)
        delay_time_title = QtWidgets.QLabel()
        delay_time_title.setFixedSize(25, 15)
        delay_time_title.setText("延时ms")
        delay_time_title.setFont(QFont("楷体", 6))
        delay_time_title.setAlignment(Qt.AlignCenter)
        layout.addWidget(delay_time_title)
        # 布局
        weight = QtWidgets.QWidget()
        weight.setLayout(layout)
        item = QtWidgets.QListWidgetItem()
        item.setSizeHint(QSize(370, 15))
        self.Command_List_Widget.addItem(item)
        self.Command_List_Widget.setItemWidget(item, weight)

